import http from "./http";


//根据id查询 播放音乐
async function getMusic(musicId) {
    try {
        const response = await http({
            method: 'get',
            url: '/getMusic/' + musicId,

        });
        return response.data;
    } catch (error) {
        console.log(error);
    }
}
//根据用户id获取全部首页歌曲
async function getAllMusicByUserId(userId) {
    try{
        const response = await http({
            method:"get",
            url:'/getAllMusicByUserId/'+userId,
        })
        return response.data
    } catch(error){
        console.log(error);
        
    }
}

/*获取首页音乐列表 模糊查询 */
async function getHomeMusicList(userId,musicTitle) {
    try {
        const response = await http({
            method:"get",
            url:"/getHomeMusicList",
            params:{
                userId:userId,
                musicTitle:musicTitle,
            }
        })
        return response.data
    } catch (error) {
        console.log(error);
    }
}


/*收藏------------------------------------------ */
//根据用户id模糊查询收藏夹音乐
async function getUserFavoriteMusicList(userId,musicTitle) {
    try {
        const response = await http({
            method: 'get',
            url: '/getUserFavoriteMusic',
            params:{
                userId:userId,
                musicTitle:musicTitle,
            }
        });
        return response.data;
    } catch (error) {
        console.log(error);
    }
}
//取消收藏音乐
async function removeFavorite(userId, musicId) {
    try {
        const response = await http({
            method: 'post',
            url: '/removeFavorite',
            data: {
                userId: userId,
                musicId: musicId
            }
        });
        return response.data;
    } catch (error) {
        console.log(error);
    }
}
//添加收藏
async function addFavorite(userId, musicId) {
    try {
        const response = await http({
            method: 'post',
            url: '/addFavorite',
            data: {
                userId: userId,
                musicId: musicId
            }
        });
        return response.data;
    } catch (error) {
        console.log(error);
    }
}


export default {getHomeMusicList,getAllMusicByUserId, getMusic, addFavorite, removeFavorite,getUserFavoriteMusicList}